<?php

namespace app\admin\model;

use think\Model;

class ArticleCate extends Model
{
    // 表名
    protected $name = 'article_cate';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'type_text',
        'module_type_text',
        'is_open_text',
        'is_open1_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $row->save(['sort' => $row['id']]);
        });
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'),'0' => __('Status 0')];
    }

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'),'2' => __('Type 2')];
    }     

    public function getModuleTypeList()
    {
        return ['1' => __('Module_type 1'),'2' => __('Module_type 2'),'3' => __('Module_type 3'),'99' => __('Module_type 99')];
    }     

    public function getIsOpenList()
    {
        return ['1' => __('Is_open 1'),'0' => __('Is_open 0')];
    }     

    public function getIsOpen1List()
    {
        return ['1' => __('Is_open1 1'),'0' => __('Is_open1 0')];
    }     


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getModuleTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['module_type'];
        $list = $this->getModuleTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsOpenTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['is_open'];
        $list = $this->getIsOpenList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsOpen1TextAttr($value, $data)
    {        
        $value = $value ? $value : $data['is_open1'];
        $list = $this->getIsOpen1List();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
